/**
 * 获取GET参数
 * @param {type} name
 * @returns {unresolved}
 */
var getParameter = function(name) {
    var str = window.location.search;
    var index = str.indexOf("?" + name + "=");
    if (index == -1) {
        index = str.indexOf("&" + name + "=");
    }
    if (index == -1) {
        return null;
    }
    var end = str.indexOf("&", index + 1);
    if (end == -1) {
        return str.substring(index + 2 + name.length);
    } else {
        return str.substring(index + 2 + name.length, end);
    }
};
/**
 * ajax 调用
 * @param {type} name
 * @returns {unresolved}
 */
function jsonAjax(url,type,data,callback) {
    $.ajax({
        url:url,
        type: type,
        contentType:"application/json",
        dataType:'json',
        async:false,
        data:data,
        headers:{
            "x-access-id": accessId,
            "x-access-token": accessToken,
            "x-ua": ua
        },
        success: callback
    });
}

/**
 * ajax 调用的url
 * @param {type} name
 * @returns {unresolved}
 */
var genUrl = function (uri) {
    var domain = document.domain;
    if(domain.indexOf("local")>-1){
        domain=domain+":8080";
    }else{
        domain=domain;
    }
    var apiMode = "/api";
    if(document.domain.indexOf("local")>-1 || document.domain.indexOf("test")>-1){
        apiMode = "/api1";
    }
    return document.location.protocol + "//"  + domain + apiMode + uri;
}

/**
 * 时间格式为YY:HH:SS
 * @param {type} name
 * @returns {unresolved}
 */
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};